<?php
/**
 * Created by PhpStorm.
 * User: 睿
 * Date: 2017-12-13
 * Time: 16:48
 */

namespace app\store\controller;


use controller\BasicAdmin;

class Screen extends BasicAdmin
{
    /**
     * @return mixed
     */
    public function index()
    {
        $store_id = session('user')['store_id'];
        $this->assign('title', '数据大屏');
        $this->assign('store_id', $store_id);
        return view();
    }

    /**
     * 会员各门店 周／月／年／总消费额
     */
    public function li()
    {
        $id = input('id');
        $time = input('time');
        $view = db('view_order')->where('store_id', $id)->wheretime('addtime', $time)->group('uid')->field('sum(final_amount) sum,realname,mobile')->order('sum desc')->select();

        //排名，同名同号
        $n = 0;
        foreach ($view as $key => &$value) {
            $n++;
            if ($key > 0){
                if ($value['sum'] == $view[$key - 1]['sum'])
                    $value['n'] = $view[$key - 1]['n'];
                else
                    $value['n'] = $n;
            }
            else
                $value['n'] = 1;
        }
        halt($view);
    }

    /**
     * 最大额
     */
    public function max()
    {
        $id = input('id');
        $max = db('order')->where('store_id', $id)->max('final_amount');
        $users = db('order')->where('store_id', $id)->where('final_amount', $max)->select();
        halt($users);
    }
}